<?php
namespace frontend\models;

use yii\base\Model;
use yii\base\InvalidParamException;
use common\models\User;
use Yii;

/**
 * Password reset form
 */
class ResetPasswordForm extends Model
{

    public $password;
    public $tel;
    public $code;
    public $rpassword;
    /**
     *
     * @var \common\models\User
     */
    private $_user;
   

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [
                ['password','tel','code','rpassword'],
                'required'
            ],
            [
                'password',
                'string',
                'min' => 6
            ],
            [ 
                'tel',
                'number',
            ],
            ['rpassword','compare','compareAttribute'=>'password','message'=>'两次密码不一致'],
            ['code','integer']
        ];
    }

    /**
     * Resets password.
     *
     * @return boolean if password was reset.
     */
    public function resetPassword()
    {
        $user = User::findOne(Yii::$app->user->id);
        $user->setPassword($this->password);
        
        return $user->save(false);
    }
    
}
